/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Competente;





import adsreis.com.Beans.ClientesBean;
import adsreis.com.Beans.CondsBean;
import adsreis.com.Beans.FormasBean;
import adsreis.com.Beans.FuncionariosBean;
import adsreis.com.Beans.OSBean;
import adsreis.com.Beans.OSdetBean;


import adsreis.com.Beans.ProdutosBean;
import adsreis.com.Beans.StatusOSBean;

import adsreis.com.Controls.ClientesControl;
import adsreis.com.Controls.CondsControl;
import adsreis.com.Outros.ConvertDouble;
import adsreis.com.Controls.FormasControl;
import adsreis.com.Controls.FuncionariosControl;
import adsreis.com.Controls.OSControl;
import adsreis.com.Controls.OSdetControl;
import adsreis.com.Controls.ProdutosControl;
import adsreis.com.Controls.StatusOSControl;
import adsreis.com.acessobd.AcessoMySql;
import br.com.caelum.stella.inwords.FormatoDeExtenso;
import br.com.caelum.stella.inwords.FormatoDeReal;
import br.com.caelum.stella.inwords.NumericToWordsConverter;
import java.awt.AWTKeyStroke;
import java.awt.KeyboardFocusManager;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.Date;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Pauroenriki
 */
public class OS extends javax.swing.JFrame {
    DefaultTableModel tmItens = new DefaultTableModel(null, new String []{"Codigo", "Descrição", "Marca", "Valor", "Quatidade"});
    DefaultTableModel tmOSFinalizadas = new DefaultTableModel(null, new String[] {"Codigo", "Status", "Cliente","Vendedor", "Data da OS", "Forma Pgto", "Cond. Pgto", "ID"});
    
    ListSelectionModel lsmOSFinalizadas;
    
    String tipocadastro;
    String tipoalter;
    DefaultTableModel tmOS = new DefaultTableModel (null, new String[] {"Codigo", "Produto", "Unit","Quantidade", "Montante"});
    //ListSelectionModel lsmFuncionarios;
    List<FuncionariosBean> funcionarios;
    List<ProdutosBean> produtos;
    List<ClientesBean> clientes;
    List<FormasBean> formas;
    List<CondsBean> conds;
    String extenso;
    List<StatusOSBean> statusOS;
    List<OSBean> os = new ArrayList<>();
    public static List<OSBean> osfinalizadas = new ArrayList<>();
    //public static List<OSdetBean> itensOs = new ArrayList<>();
    public static List<OSdetBean>osdet = new ArrayList<>();
    List<ProdutosBean> produt = new ArrayList<>();
    ListSelectionModel lsmOs;
    String codprod;
    String busca;
    String codprod1;
    String quantidade;
    String unit;
    public static Integer codos;
    Integer codstatus;
    String Nproduto;
    String valor;
    Integer remover;
    Integer qtdestoque;
    String verificaduplicidade = "";
    Integer qtd;
    String codproduto;
    String User;
    public static Integer Funcionariologado;
    Funcionarios FrameFuncionarios;
    double subtotal = 0;
    double desconto = 0;
    double total = 0;
    double servicoterceiro = 0;
    double mo = 0;
    double valorpago;
    double resta;
    Date verificardata;
    
    public static Date dat;
    public static String codp;
    public static Integer fun = 0;
    public static String cli;
    public static String form;
   public static  String cond;
    public static Integer cli1 = 0;
    public static Integer form1 = 0;
    public static Integer cond1 = 0;
    public static Integer status1 = 0;
    Integer Acesso;
    
    
    
    
    
    
   /* protected void listarClientes(){
        ClientesControl cli = new ClientesControl();
        clientes = cli.listarClientes("%%");
        cbClientes.removeAllItems();
        for (int i = 0; i < clientes.size(); i++){
            cbClientes.addItem(clientes.get(i).getNome());
        }
    }*/
     private void listarFuncionarios(){
        String st;
        st = tfFuncionario.getText();
        FuncionariosControl cli = new FuncionariosControl();
        List<FuncionariosBean> sob;
        sob = cli.listarFuncionarios("%" + st + "%");
        FuncionariosBean sb = new FuncionariosBean();
        //cbClientes.removeAllItems();
        for (int i = 0; i < sob.size(); i++){
            //cbClientes.addItem(clientes.get(i).getNome());
             sb.setCodFuncionario(sob.get(i).getCodFuncionario());
             sb.setNome(sob.get(i).getNome());
             
        }
    
        tfFuncionario.setText(sb.getNome());
        fun = sb.getCodFuncionario();
    }
    private void listarStatus(){
        String st;
        st = tfStatus.getText();
        StatusOSControl cli = new StatusOSControl();
        List<StatusOSBean> sob;
        sob = cli.listarStatus("%" + st + "%");
        StatusOSBean sb = new StatusOSBean();
        //cbClientes.removeAllItems();
        for (int i = 0; i < sob.size(); i++){
            //cbClientes.addItem(clientes.get(i).getNome());
             sb.setCodstatusos(sob.get(i).getCodstatusos());
             sb.setStatusos(sob.get(i).getStatusos());
             
        }
    
        tfStatus.setText(sb.getStatusos());
        status1 = sb.getCodstatusos();
    }
    
    /*protected void listarStatus(){
        StatusOSControl status = new StatusOSControl();
        statusOS = status.listarStatus("%%");
        cbStatus.removeAllItems();
        for (int i = 0; i < statusOS.size(); i++){
            cbStatus.addItem(statusOS.get(i).getStatusos());
            
        }
    }*/
    
    private void listarClientes(){
        String cl;
        cl = tfCliente.getText();
        ClientesControl cli = new ClientesControl();
        List<ClientesBean> cc;
        cc = cli.listarClientes("%" + cl + "%");
        ClientesBean cb = new ClientesBean();
        //cbClientes.removeAllItems();
        for (int i = 0; i < cc.size(); i++){
            //cbClientes.addItem(clientes.get(i).getNome());
             cb.setCodCliente(cc.get(i).getCodCliente());
             cb.setNome(cc.get(i).getNome());
        }
    
        tfCliente.setText(cb.getNome());
        cli1 = cb.getCodCliente();
    }
    
    
    
    protected void listarFormas(){
        String form;
        form = tfForma.getText();
        FormasControl foma = new FormasControl();
        List<FormasBean> cc;
        cc = foma.listarFormas("%" + form + "%");
        FormasBean fb = new FormasBean();
        //cbClientes.removeAllItems();
        for (int i = 0; i < cc.size(); i++){
            //cbClientes.addItem(clientes.get(i).getNome());
             fb.setCodForma(cc.get(i).getCodForma());
             fb.setForma(cc.get(i).getForma());
             
        }
    
        tfForma.setText(fb.getForma());
        form1 = fb.getCodForma();
    }
    
    protected void listarConds(){
        String cond;
        cond = tfCond.getText();
        CondsControl condi = new CondsControl();
        List<CondsBean> cc;
        cc = condi.listarConds("%" + cond + "%");
        CondsBean cb = new CondsBean();
        //cbClientes.removeAllItems();
        for (int i = 0; i < cc.size(); i++){
            //cbClientes.addItem(clientes.get(i).getNome());
             cb.setCodCond(cc.get(i).getCodCond());
             cb.setCond(cc.get(i).getCond());
            
        }
    
        tfCond.setText(cb.getCond());
        cond1 = cb.getCodCond();
    }
   
    
    /**
     * Creates new form Vendas
     */
    public OS() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException{
        initComponents();
        //listarClientes();
        //listarStatus();
        
        //listarFormas();
        //listarConds();
        ftfQuantidade.setValue(1);
        setIcon();
        Login ff = new Login();
        Acesso = ff.nAcesso;
        User = ff.acessivel;
        Funcionariologado = ff.idfunc;
        this.setTitle("CADASTRAR OS - Usuário: " + User);
        //btNovo.setVisible(false);
        Nacesso();
        
        // Colocando enter para pular de campo 
HashSet conj = new HashSet(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); 
conj.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
conj.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, conj); 

        
        
    }
    
    private void Nacesso(){
        
        switch (Acesso){
            case 0:
                btCancelarOS.setVisible(false);
               btAlterar.setVisible(false);
                btExcluir.setVisible(false);
                btExcluirVenda.setVisible(false);
            case 1:
                btAlterar.setVisible(false);
                btExcluir.setVisible(false);
                btExcluirVenda.setVisible(false);
        }
        
        
    }
    
    private void setIcon() {
        //etIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("a.png")));﻿
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Icons/icon.png")));
    }
    
    
    
    
    protected void novoCadastro(){
        OSControl vc = new OSControl();
     codos = vc.buscarCodigoUltimaOS()+ 1;
     habilitarCampos();
     btNovo.setEnabled(false);
     lblCodigo.setText(String.valueOf(codos));
     OSBean ob = new OSBean();
     
     
            
            ob.setCodOs(codos);
            os.add(ob);
     
     
     
     
     tfProduto.requestFocus();
     
     while (tmOS.getRowCount()>0){
            tmOS.removeRow(0);            
        }
     ftfQuantidade.setValue(null);
     SimpleDateFormat formato = new SimpleDateFormat("dd / MM / yyyy");
     java.util.Date d = new java.util.Date();
     String dd;
     dd = String.valueOf(formato.format(d));
     lblData.setText(dd);
     //ftfDataVencimento.setDate(d);
     
     ftfSubtotal.setValue(0);
     ftfDesconto.setValue(0);
     ftfTotal.setValue(0);
     ftfMO.setValue(0);
     ftfServicoTerceiros.setValue(0);
     ftfQuantidade.setValue(1);
     ftfValorPago.setValue(0);
     ftfResta.setValue(0);
    
            
    }
    
    
    public void habilitarCampos(){
     //cbClientes.setEnabled(true);
    
     //cbFuncionarios.setEnabled(true);
     //cbFormas.setEnabled(true);
     //cbConds.setEnabled(true);
     ftfQuantidade.setEnabled(true);
     ftfDesconto.setEnabled(true);
     ftfTotal.setEnabled(true);
     ftfSubtotal.setEnabled(true);
     btFinalizar.setEnabled(true);
     btInserir.setEnabled(true);
     //cbStatus.setEnabled(true);
     //ftfDataVencimento.setEnabled(true);
     ftfServicoTerceiros.setEnabled(true);
     tfObs.setEnabled(true);
     ftfMO.setEnabled(true);
     tfProduto.setEnabled(true);
     tfFuncionario.setEnabled(true);
     ftfValorPago.setEnabled(true);
     ftfResta.setEnabled(true);
    }
    
    
    public void desabilitarCampos(){
     //cbClientes.setEnabled(false);
     //cbFuncionarios.setEnabled(false);
     //cbFormas.setEnabled(false);
     //cbConds.setEnabled(false);
     btFinalizar.setEnabled(false);
     ftfQuantidade.setEnabled(false);
     ftfDesconto.setEnabled(false);
     ftfTotal.setEnabled(false);
     ftfSubtotal.setEnabled(false);
     ftfValorPago.setEnabled(false);
     ftfResta.setEnabled(false);
     //cbStatus.setEnabled(false);
     //ftfDataVencimento.setEnabled(false);
     ftfServicoTerceiros.setEnabled(false);
     tfObs.setEnabled(false);
     ftfMO.setEnabled(false);
     tfProduto.setEnabled(false);
     tfFuncionario.setEnabled(false);
     btComprovante1.setEnabled(false);
     btComprovante.setEnabled(false);

     ftfQuantidade.setText(null);
     ftfDesconto.setText(null);
     ftfTotal.setText(null);
     ftfSubtotal.setText(null);
     tfProduto.setText("");
     
     
     
    }
    
    public void excluirOS(){
        if (tbOSFinalizadas.getSelectedRow() != -1){
            int resposta = JOptionPane.showConfirmDialog(this, "Tem certeza que quer excluir o orçamento selecionado?", "Confirmação",
                    JOptionPane.YES_NO_OPTION);
            if (resposta == JOptionPane.YES_OPTION){
                OSControl vc = new OSControl();
                vc.excluirOS(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCodOs());
                ProdutosControl pc = new ProdutosControl();
                ProdutosBean pb = new ProdutosBean();
                /*for(int i=0; i<itensOs.size(); i++){
                    pb.setCodProduto(itensOs.get(i).getIdproduto());
                    pb.setQtdEstoque(itensOs.get(i).getQtdOs());
                pc.incluirQtdEstoque(pb);
                }*/
                for(int i=0; i<osdet.size(); i++){
                    pb.setCodProduto(osdet.get(i).getIdproduto());
                    pb.setQtdEstoque(osdet.get(i).getQtdOs());
                pc.incluirQtdEstoque(pb);
                }
                
                //btAlterar.setEnabled(false);
                btExcluirVenda.setEnabled(false);
                pesquisarOS();
            }
        }
    }
    
    public void excluirOSDet(){
        if (tbOSFinalizadas.getSelectedRow() != -1){
         
                OSdetControl vc = new OSdetControl();
                vc.excluirOSDET(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCodOs());
                
                
               
                //btAlterar.setEnabled(false);
                btExcluirVenda.setEnabled(false);
            
        }
    }
    
    
    
    
    protected void cadastrarOS(){
     tbOSFinalizadas.getSelectionModel().clearSelection();
        if(osdet == null ){
            JOptionPane.showMessageDialog(this, "É necessário que todos os campos sejam preenchidos!");
        } else{
            try{
            OSControl oc = new OSControl();
            SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
            java.util.Date d = new java.util.Date();
            Date data = Date.valueOf(formato.format(d));
            OSdetControl odc =new OSdetControl();
            
            OSBean ob = new OSBean();
            
            
            
           // java.util.Date datav;
            //datav = ftfDataVencimento.getDate();
            //Date datavali = Date.valueOf(formato.format(datav));
            
            
            
            
            
            for (int i = 0; i < os.size(); i++){
                
                //os.get(i).setIDCliente(clientes.get(cbClientes.getSelectedIndex()).getCodCliente());
                os.get(i).setIDCliente(cli1);
                
                os.get(i).setIDStatus(status1);
                //vendas.get(i).setIDFuncionario(funcionarios.get(cbFuncionarios.getSelectedIndex()).getCodFuncionario());
                os.get(i).setIDFuncionario(fun);
                os.get(i).setIDForma(form1);
                os.get(i).setIDCond(cond1);
                os.get(i).setDataos(data);
                os.get(i).setCodOs(codos);
                os.get(i).setSubTotal(subtotal);
                os.get(i).setServicoTerceiro(servicoterceiro);
                os.get(i).setMaoObra(mo);
                os.get(i).setDesconto(desconto);
                os.get(i).setTotal(total);
                os.get(i).setObs(tfObs.getText());
                os.get(i).setValorPago(valorpago);
                os.get(i).setResta(resta);
                oc.cadastrarOS(os.get(i));
                
            }
            
            
            for (int i = 0; i < osdet.size(); i++){
                osdet.get(i).getIDOs(); 
                osdet.get(i).getIdproduto();
                osdet.get(i).getQtdOs();
                osdet.get(i).getPreco();
                odc.cadastrarItem(osdet.get(i));
                System.out.println(osdet.get(i).getIdproduto());
                
            }
            
                    
            for (int t = 0; t < produt.size();t++){ //Removendo Itens do estoque
            produt.get(t);
            ProdutosControl pb = new ProdutosControl();
            pb.retirarQtdEstoque(produt.get(t));
                }
            
            
            
            JOptionPane.showMessageDialog(this, "Orçamento cadastrado com Sucesso!");
            desabilitarCampos();
             btNovo.setEnabled(true);
             fechar();
             
            } catch(Exception ex){
                ex.printStackTrace();
                JOptionPane.showMessageDialog(this, "Erro ao cadastrar Orçamento!");
                fechar();
                
            }

            
        }
      
    }

    
    protected boolean verificarDuplicidade(){
        
        for(int i = 0; i<osdet.size(); i++){//produt
               
               verificaduplicidade = osdet.get(i).getIdproduto();
               
        
               if(verificaduplicidade.equals(codprod)){ //verificaduplicidade == null ? codprod != null : 
                 JOptionPane.showMessageDialog(this, "Item em duplicidade!");
                   return false;
                 
               }
        }
            
               
        return true;
        
    }
    
    
    private String buscaprod(String prod){
        ProdutosBean pb = new ProdutosBean();
        OSControl oc = new OSControl();
        oc.listarProdutos(prod);
        
        
        produtos = OSControl.produtos1;
        for (int i =0; i < produtos.size(); i++){
          pb.setCodProduto(produtos.get(i).getCodProduto());
       }
        
        
        codprod = pb.getCodProduto();
        
        
        return codprod;
    }
    
    
    
    
    
    protected void incluirProduto(){
        
        //while (produtos.size()>0){
          //  produtos.remove(0);            
        //}
        
        ProdutosBean produto = new ProdutosBean();
        
        
            //produto.setCodProduto(tfProduto.getText());
            //codprod = produto.getCodProduto();
           busca = tfProduto.getText();
               OSControl oc = new OSControl();
            buscaprod(busca);
            try {
          if (codprod == null) {
                JOptionPane.showMessageDialog(this, "Produto não cadastrado!");
                
            }else  if (verificarQuantidade() && verificarQuantidadeEstoque() && verificarDuplicidade()){
            OSdetBean vb = new OSdetBean();
            vb.setIDOs(codos);
            vb.setIdproduto(codprod);
            vb.setQtdOs(Integer.parseInt(String.valueOf(ftfQuantidade.getValue())));
            
            //buscaprod(busca);              //¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
            //oc.listarProdutos(codprod);   *********************************
            produtos = OSControl.produtos1;
            Double preco = null;
            for (int i =0; i < produtos.size(); i++){
           produto.setCodProduto(produtos.get(i).getCodProduto());
           produto.setDescricao(produtos.get(i).getDescricao());
           produto.setMarca(produtos.get(i).getMarca());
            produto.setVlrVenda(produtos.get(i).getVlrVenda());
           preco = produtos.get(i).getVlrVenda();
       }
            vb.setPreco(preco);
            
            
            
            produto.setQtdEstoque(Integer.parseInt(String.valueOf(ftfQuantidade.getValue())));
            produt.add(produto);
            osdet.add(vb);
            
            
            
            unit = String.valueOf(produto.getVlrVenda());
            Nproduto = produto.getDescricao();
            quantidade = String.valueOf(ftfQuantidade.getValue());
            codprod1 = String.valueOf(codprod);
            valor = String.valueOf(produto.getVlrVenda() * Integer.parseInt(quantidade));
            String [] campos = new String [] { codprod1, Nproduto, unit, quantidade, valor};
            tmOS.addRow(campos);
            
           /* 
            Double to;
            Double des;
            
            
            to = Double.parseDouble(ftfTotal.getText());
            des = Double.parseDouble(ftfDesconto.getText());
            Double  Sub;
            Sub = Double.parseDouble(ftfSubtotal.getText());
            
            subtotal = Double.parseDouble(valor) + Sub;
            ftfSubtotal.setValue(subtotal);
            System.out.println(subtotal);
            
            */
            
            
            
        }
        
        
        else {
            ftfQuantidade.requestFocus();
        }
        
        
        } catch(Exception ex){
            
            //JOptionPane.showMessageDialog(this, "Digite corretamente o CÓDIGO ou DESCRIÇÃO do Produto", "ERRO", JOptionPane.ERROR_MESSAGE);  
                tfProduto.requestFocus();
        }
        
        
            
            while (oc.produtos1.size()>0){
            oc.produtos1.remove(0);
            
            }
            while (produtos.size()>0){
            produtos.remove(0);
            
            }
            while (osfinalizadas.size()>0){
            osfinalizadas.remove(0);
            
            }
    
            Subtotal(); // alterando o valor do Subtotal
    }
    
    protected boolean verificarQuantidadeEstoque(){               //verifica se a quantidade pedida pelo usuário, tem saldo positivo no estoque
        //try{
            ProdutosControl pc = new ProdutosControl();
            
            
            ProdutosBean p = pc.buscarQtd(codprod);         //Verificando o Banco de dados
            qtdestoque = p.getQtdEstoque();
            Integer qtd2;
            qtd2 = Integer.parseInt(ftfQuantidade.getText());
            
            
            
            
            if (qtdestoque >= qtd2  && qtdestoque > 0){
                return true;
            }else{
        //}catch (Exception ex){
          //  ex.getMessage();
            JOptionPane.showMessageDialog(this, "O Produto selecionado está em falta!" + "\n Veja a quantidade em estoque: " + qtdestoque);
        }
        return false;
    }
    
    
    
    protected boolean verificarQuantidade(){ //verifica se o usuario inseriu quantidade valida antes de inserir o produto na tabela
       
        try{
            if (Integer.parseInt(String.valueOf(ftfQuantidade.getValue())) > 0){
                return true;
            }
        }catch (NumberFormatException ex){
            //ex.printStackTrace();
            JOptionPane.showMessageDialog(this, "Quantidade inválida!");
        }
        return false; 
        
    }
    
    protected void removerProduto(){
        if (tbOS.getSelectedRow() != -1){               //exclui produto selecionado
            int resposta = JOptionPane.showConfirmDialog(this, "Tem certeza que quer excluir o produto selecionado?", "Confirmação",
                    JOptionPane.YES_NO_OPTION);
            if (resposta == JOptionPane.YES_OPTION){
                remover = tbOS.getSelectedRow();
                //itensOs.remove(tbOS.getSelectedRow());
                osdet.remove(tbOS.getSelectedRow());
                produt.remove(tbOS.getSelectedRow());
                tmOS.removeRow(tbOS.getSelectedRow());
                
                
                btExcluir.setEnabled(false);
            ftfQuantidade.setValue(null);
        
    }
    }
    }
    
    protected void removerProdutoAlter(){
        if (tbOS.getSelectedRow() != -1){               //exclui produto selecionado
            int resposta = JOptionPane.showConfirmDialog(this, "Tem certeza que quer excluir o produto selecionado?", "Confirmação",
                    JOptionPane.YES_NO_OPTION);
            if (resposta == JOptionPane.YES_OPTION){
               // remover = tbOS.getSelectedRow();
               // osdet.remove(tbOS.getSelectedRow());
               // produt.remove(tbOS.getSelectedRow());
                OSdetControl odc = new OSdetControl();
                
                String pr;
                Integer os;
                Integer qt;
                qt = osdet.get(tbOS.getSelectedRow()).getQtdOs();
                pr = osdet.get(tbOS.getSelectedRow()).getIdproduto();
                os = osdet.get(tbOS.getSelectedRow()).getIDOs();
                odc.excluirItemDET(os, pr);
                osdet.remove(tbOS.getSelectedRow());
                tmOS.removeRow(tbOS.getSelectedRow());
                ProdutosControl pc = new ProdutosControl();
                ProdutosBean pb = new ProdutosBean();
                pb.setCodProduto(pr);
                pb.setQtdEstoque(qt);
                pc.incluirQtdEstoque(pb);
                btExcluir.setEnabled(false);
            ftfQuantidade.setValue(null);
        
    }
    }
    }
    
    
    protected void tbVendasLinhaSelecionada(JTable tb){             //Ao selecionar um item na tabela, os dados serão preenchidos nos campos
        if (tb.getSelectedRow() != -1){
            btExcluir.setEnabled(true);
            //lblCodigo.setText(String.valueOf(produtos.get(tb.getSelectedRow()).getCodProduto()));
            //cbClientes.setSelectedIndex(tbVendas.getSelectedRow());
            //cbProdutos.setSelectedIndex(tbOrcamentos.getSelectedRow());
            //cbFuncionarios.setSelectedIndex(tbVendas.getSelectedRow());
            //tfQtd.setInt(String.valueOf(tbVendas.getSelectedRow())).getQtd();
            //ftfQuantidade.setText(String.valueOf(orcamentos.get(tbOrcamentos.getSelectedRow()).getQtd()));
            
            
        } else {
            
        }
    }
    
    public void pesquisarOS(){
        
        
         ClientesBean cb = new ClientesBean();
        OSControl oc = new OSControl();
        //if (ftfDataInicio.getValue() == null){
        if (dataIni.getDate()== null){
            JOptionPane.showMessageDialog(this, "Informe a data Inicial!");
            dataIni.requestFocus();
        //} else if (ftfDataFim.getValue() == null){
            } else if (dataFim.getDate() == null){
            JOptionPane.showMessageDialog(this, "Informe a data Final!");
            dataFim.requestFocus();
        } else {
            while (tmOSFinalizadas.getRowCount() > 0){
                tmOSFinalizadas.removeRow(0);
               
            }
            while (osfinalizadas.size()>0){
            osfinalizadas.remove(0);            
        }
            SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
            //java.util.Date dataInicio = (java.util.Date) ftfDataInicio.getValue();
            java.util.Date dataInicio = (java.util.Date) dataIni.getDate();
            //System.out.println(formato.format(dataInicio));
            //java.util.Date dataFim = (java.util.Date) ftfDataFim.getValue();
            java.util.Date dataFinal = (java.util.Date) dataFim.getDate();
            osfinalizadas = oc.listarOS(Date.valueOf(formato.format(dataInicio)), Date.valueOf(formato.format(dataFinal)));
            
           // verificardata = orcamentospendentes.get(tbOrcamentosPendentes.getSelectedRow()).getDataValidade();
            //String d1;
            
            //d1 = String.valueOf(dateControl1.getDate());
           // System.out.println(d1);
            
            
            String [] campos = new String[] {null, null, null, null, null, null, null, null};
            
             for (int i = 0; i < osfinalizadas.size(); i++){ 
            //for (int i = 0; i < orcamentospendentes.size(); ++i){    
                //Carregando tabela de vendas finalizadas
                //String [] campos = new String[] {codp, cli, null, null, null, null};
                //codp = String.valueOf(vendasfinalizadas.get(i).getCodVenda());
                //cli = String.valueOf(vendasfinalizadas.get(i)clientes.getNome());
                
                
                
                tmOSFinalizadas.addRow(campos);
                
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getCodOs(), i, 0);
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getStatusOs(), i, 1);
                //tmVendasFinalizadas.setValueAt(vendasfinalizadas.get(i).getIDCliente(), i, 1);
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getNomecli(), i, 2);
                //tmVendasFinalizadas.setValueAt(vendasfinalizadas.get(i).getIDFuncionario(), i, 3);
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getNomefunc(), i, 3);
                Date ddd;
                
                ddd = osfinalizadas.get(i).getDataos();
                SimpleDateFormat formato2 = new SimpleDateFormat("dd / MM / yyyy");
                 java.util.Date d = ddd;
                String dd;
                dd = String.valueOf(formato2.format(d));
            
               tmOSFinalizadas.setValueAt(dd, i, 4);
               /*Date dv;
                String ddv;
               dv = osfinalizadas.get(i).getDataValidade();
               ddv = String.valueOf(formato2.format(dv));
               tmOSFinalizadas.setValueAt(ddv, i, 5);*/
                
                //tmVendasFinalizadas.setValueAt(vendasfinalizadas.get(i).getIDForma(), i, 6);
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getFormaPgto(), i, 5);
                //tmVendasFinalizadas.setValueAt(vendasfinalizadas.get(i).getIDCond(), i, 8);
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getCondPgto(), i, 6);
                tmOSFinalizadas.setValueAt(osfinalizadas.get(i).getIDStatus(), i, 7);
                
                
                
                
            
               }
            
            if (osfinalizadas.size() == 0){
                JOptionPane.showMessageDialog(this, "Nenhum registro encontrado!");
            
        }
    }
    }
    
    //@SuppressWarnings("empty-statement")
    
    
   /* public void verificarData(){
        Date compararvencimento = new Date(System.currentTimeMillis());
        verificardata = orcamentospendentes.get(tbOrcamentosPendentes.getSelectedRow()).getDataValidade();
        if(verificardata.before(compararvencimento)){
            lblDtVencimento.setForeground(Color.red);
        }else{
        
        lblDtVencimento.setForeground(Color.black);
        }
     //verificardata = null;   
    } */
    
    
    
    public void aprovarOS(){
        OSBean ob =new OSBean();
        OSControl oc = new OSControl();
        codos = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCodOs();
        if(codos != null && codstatus != null){
            ob.setCodOs(codos);
            ob.setIDStatus(codstatus);
            oc.alterarStatus(ob);
            JOptionPane.showMessageDialog(this, "Status da OS foi alterado");
            tbOSFinalizadas.getSelectionModel().clearSelection();
            //fechar();
           // ftfDataVencimento.requestFocus();
           // ftfDataVencimento.setSelectableDateRange(null, null);
                   
        }else{
            JOptionPane.showMessageDialog(this, "Erro ao mudar Status da OS");
        }
        
        btAprovar.setEnabled(false);
        btCancelarOS.setEnabled(false);
        btAguardando.setEnabled(false);
        
    }
    
    private void Subtotal(){
       subtotal = 0;
        OSdetControl odc = new OSdetControl();
        Double preco;
        Integer qtd;
        Double semitotal ;
        for (int i = 0; i < osdet.size(); i++){
                osdet.get(i).getIDOs(); 
                osdet.get(i).getIdproduto();
                qtd = osdet.get(i).getQtdOs();
                preco = osdet.get(i).getPreco();
                semitotal = preco * qtd;
                subtotal = subtotal + semitotal;
                }
        ConvertDouble cvd = new ConvertDouble();
        String mo1;
        mo1 =ftfMO.getText();
        mo = cvd.converterDoubleString2(mo1);
        String servicoterceiro1;
        servicoterceiro1 = ftfServicoTerceiros.getText();
        servicoterceiro = cvd.converterDoubleString2(servicoterceiro1);
        String desconto1;
        desconto1 = ftfDesconto.getText();
        desconto = cvd.converterDoubleString2(desconto1);
        
        String subtotal1;
        subtotal1 = String.valueOf(subtotal);
        subtotal = cvd.converterDoubleString2(subtotal1);
        total = (subtotal - desconto) + servicoterceiro + mo;
        String total1;
        total1 = String.valueOf(total);
        total = cvd.converterDoubleString2(total1);
        
        
        /*mo = Double.parseDouble(ftfMO.getText().trim());
        servicoterceiro = Double.parseDouble(ftfServicoTerceiros.getText().trim());
        desconto = Double.parseDouble(ftfDesconto.getText().trim());*/
        
        
        total = (subtotal - desconto) + servicoterceiro + mo;
        
        String vpago;
        vpago = ftfValorPago.getText();
        valorpago = cvd.converterDoubleString2(vpago);
        String resta1;
        resta1 = String.valueOf(total - valorpago);
        resta = cvd.converterDoubleString2(resta1);
        ftfResta.setValue(resta);
        
        
        //ftfTotal.setText(String.valueOf(total));
        ftfTotal.setValue(total);
        ftfSubtotal.setValue(subtotal);
       
        
        
        
    }
    
    private void alterarOS(){
        SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
        OSBean osb = new OSBean();
        OSControl osc =new OSControl();
        OSdetControl odc= new OSdetControl();
        /*osb.setCodOs(os.get(tbOSFinalizadas.getSelectedRow()).getCodOs());
        osb.setIDCliente(os.get(tbOSFinalizadas.getSelectedRow()).getIDCliente());
        osb.setIDForma(os.get(tbOSFinalizadas.getSelectedRow()).getIDForma());
        osb.setIDCond(os.get(tbOSFinalizadas.getSelectedRow()).getIDCond());
        osb.setDatatrocaoleo(os.get(tbOSFinalizadas.getSelectedRow()).getDatatrocaoleo());
        osb.setDatatrocacorreia(os.get(tbOSFinalizadas.getSelectedRow()).getDatatrocacorreia());
        osb.setSubTotal(os.get(tbOSFinalizadas.getSelectedRow()).getSubTotal());
        osb.setServicoTerceiro(os.get(tbOSFinalizadas.getSelectedRow()).getServicoTerceiro());
        osb.setMaoObra(os.get(tbOSFinalizadas.getSelectedRow()).getMaoObra());
        osb.setDesconto(os.get(tbOSFinalizadas.getSelectedRow()).getDesconto());
        osb.setTotal(os.get(tbOSFinalizadas.getSelectedRow()).getTotal());
        osb.setObs(os.get(tbOSFinalizadas.getSelectedRow()).getObs());
       
        */
        /*for(int t = 0; t< os.size(); t++){
            os.get(t).setIDStatus(status1);
            os.get(t).setIDCliente(cli1);
            os.get(t).setIDFuncionario(Funcionariologado);
            os.get(t).setIDForma(form1);
            os.get(t).setIDCond(cond1);
            
            
        }*/
       try{ 
        osb.setCodOs(Integer.parseInt(lblCodigo.getText()));
        
        listarClientes();
        listarConds();
        listarFormas();
        listarFuncionarios();
        listarStatus();
        osb.setIDStatus(status1);
        osb.setIDCliente(cli1);
        
        osb.setIDFuncionario(fun);
        osb.setIDForma(form1);
        osb.setIDCond(cond1);
        
        
       // ConvertDouble convD = new ConvertDouble();
        
        
        /*Double doub;
        //doub = convD.converterDoubleDoisDecimais(Double.parseDouble(ftfSubtotal.getText()));
        
        
        doub = Double.parseDouble(ftfSubtotal.getText());
        //osb.setSubTotal(doub);
        osb.setSubTotal(convD.converterDoubleString1(doub));
        Double serviT;
        serviT = Double.parseDouble(ftfServicoTerceiros.getText());
        osb.setServicoTerceiro(convD.converterDoubleString1(serviT));
        Double mo;
        mo = Double.parseDouble(ftfMO.getText());
        osb.setMaoObra(convD.converterDoubleString1(mo));
        Double desconto;
        desconto = Double.parseDouble(ftfDesconto.getText());
        osb.setDesconto(convD.converterDoubleString1(desconto));
        Double total;
        total = Double.parseDouble(ftfTotal.getText());
        osb.setTotal(convD.converterDoubleString1(total));    */
        
        String doub;
        //doub = convD.converterDoubleDoisDecimais(Double.parseDouble(ftfSubtotal.getText()));
        
        
        doub = ftfSubtotal.getText();
        //osb.setSubTotal(convD.converterDoubleString1(doub));
        osb.setSubTotal(subtotal);
        String serviT;
        serviT = ftfServicoTerceiros.getText();
        osb.setServicoTerceiro(servicoterceiro);
        //String mo;
        //mo = ftfMO.getText();
        //osb.setMaoObra(convD.converterDoubleString1(mo));
        osb.setMaoObra(mo);
        //String desconto;
        //desconto = ftfDesconto.getText();
        osb.setDesconto(desconto);
        //String total1;
        //total = ftfTotal.getText();
        //osb.setTotal(convD.converterDoubleString1(total));
         osb.setTotal(total);
        osb.setValorPago(valorpago);
        osb.setResta(resta);
        
        
        
        osb.setObs(tfObs.getText());
        //offhisrocker
        
          osc.alterarOS(osb);
          desabilitarCampos();
          //pesquisarOS();
          odc.excluirOSDET(codos);
          
        
          for (int i = 0; i < osdet.size(); i++){
                osdet.get(i).getIDOs(); 
                osdet.get(i).getIdproduto();
                osdet.get(i).getQtdOs();
                odc.cadastrarItem(osdet.get(i));
                
                
            }
        
        
       while (osdet.size()>0){
            osdet.remove(0);
            
            }
       fechar();
       } catch (Exception e){
           e.printStackTrace();
       }
          
          
    }
    
    private void setarCampos(){
        lblCodigo.setText(String.valueOf(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCodOs()));
        //cbStatus.setSelectedIndex(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDStatus());
        
        
        
        codos = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCodOs();
        cli1 = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDCliente();
        status1 = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDStatus();
        form1 = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDForma();
        cond1 = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDCond();
        
        
        
        
        //cbClientes.setSelectedIndex(tbOSFinalizadas.getSelectedRow());
        //cbFormas.setSelectedIndex(tbOSFinalizadas.getSelectedRow());
        //cbConds.setSelectedIndex(tbOSFinalizadas.getSelectedRow());
       /// cbStatus.setSelectedIndex(tbOSFinalizadas.getSelectedRow());
        
        //cbClientes.setSelectedIndex(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDCliente());
       //cbFormas.setSelectedIndex(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDForma());
        //cbConds.setSelectedIndex(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getIDCond());
        tfFuncionario.setText(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getNomefunc());
        tfCliente.setText(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getNomecli());
        tfStatus.setText(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getStatusOs());
        tfForma.setText(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getFormaPgto());
        tfCond.setText(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCondPgto());
        ConvertDouble cvd = new ConvertDouble();
         String subtotal2;
       subtotal2 = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getSubTotal());
        ftfSubtotal.setText(String.valueOf(subtotal2));
        String ser;
        ser = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getServicoTerceiro());
        ftfServicoTerceiros.setText(String.valueOf(ser));
        String mo2;
        mo2 = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getMaoObra());
        ftfMO.setText(String.valueOf(mo2));
        String desconto2;
        desconto2 = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getDesconto());
        ftfDesconto.setText(String.valueOf(desconto2));
        String total2;
        total2 = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getTotal());
        ftfTotal.setText(String.valueOf(total2));
        
        String vpago2;
        vpago2 = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getValorPago());
        ftfValorPago.setText(vpago2);
        String resta2;
        resta2 = cvd.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getResta());
        ftfResta.setText(resta2);
        
        /*subtotal = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getSubTotal();
        servicoterceiro = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getServicoTerceiro();
        mo = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getMaoObra();
        desconto = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getDesconto();
        total = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getTotal();*/
        
        
        tfObs.setText(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getObs());
        
                Date ddd;
                
                ddd = osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getDataos();
                SimpleDateFormat formato2 = new SimpleDateFormat("dd / MM / yyyy");
                 java.util.Date d = ddd;
                String dd;
                dd = String.valueOf(formato2.format(d));
                OSControl oc = new OSControl();
              lblData.setText(dd);
                os = oc.listarOS1(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getCodOs());
               // OSdetControl ocd = new OSdetControl();
                osdet = oc.listarItens(codos);
         String [] campos = new String[] {null, null, null, null, null};
            Integer qt;
             for (int i = 0; i < osdet.size(); i++){ 
                tmOS.addRow(campos);
                
                tmOS.setValueAt(osdet.get(i).getIdproduto(), i, 0);
                tmOS.setValueAt(osdet.get(i).getDescricaoproduto(), i, 1);
                tmOS.setValueAt(osdet.get(i).getPreco(), i, 2);
                tmOS.setValueAt(osdet.get(i).getQtdOs(), i, 3);
                qt = osdet.get(i).getQtdOs();
                tmOS.setValueAt(osdet.get(i).getPreco() * qt, i, 4);
                tbOSFinalizadas.getSelectionModel().clearSelection();
             }
        
        /*while (itensOs.size()>0){
            itensOs.remove(0);
            
            }*/
             while (osdet.size()>0){
            osdet.remove(0);
            
            }
        Subtotal();
    }
    
    protected void tbOrcamentosPendentesLinhaSelecionada(JTable tb){             //Ao selecionar um item na tabela, os dados serão preenchidos nos campos
        
        OSControl oc = new OSControl();
        btAprovar.setEnabled(true);
        btCancelarOS.setEnabled(true);
        btAguardando.setEnabled(true);
        btAlterar.setEnabled(true);
        btComprovante.setEnabled(true);
             btComprovante1.setEnabled(true);

        
        
        
        
        
        
        //codorcamento = null;
        //dat= null;
      SimpleDateFormat formato = new SimpleDateFormat("dd / MM / yyyy");
         /*   Date compararvencimento = new Date(System.currentTimeMillis());
            int dt;
            Date dtcomp;
        dtcomp = orcamentospendentes.get(tb.getSelectedRow()).getDataValidade();
        if(compararvencimento.after(dtcomp)){
            dt = 1;
        }
        else{
            dt = 2;
        }
        switch(dt){
            case 1: lblDtVencimento.setForeground(Color.red);
            case 2: lblDtVencimento.setForeground(Color.BLACK);
                
        
    }*/
        
    
              //      lblDtVencimento.setForeground(Color.red);
        
      //      }else{
        //lblDtVencimento.setForeground(Color.BLACK);
          //  }
        try{
       if (tb.getSelectedRow() != -1){
            
             
            
            btExcluirVenda.setEnabled(true);
            
            //dat = osfinalizadas.get(tb.getSelectedRow()).getDataValidade();
            
            lblCod.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getCodOs()));
            lblClient.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getNomecli()));
            lblFunc.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getNomefunc()));
            lblForm.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getFormaPgto()));
            lblCond.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getCondPgto()));
            //cbStatus1.setSelectedIndex(orcamentospendentes.get(tb.getSelectedRow()).getIDStatus());
            lblStatus.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getStatusOs()));
            lblTelefone.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getTelefone()));
            lblCelular.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getCelular()));
            lblOperadora.setText(String.valueOf(osfinalizadas.get(tb.getSelectedRow()).getOperadora()));
            
            valorpago = osfinalizadas.get(tb.getSelectedRow()).getValorPago();
            
            ConvertDouble cvd = new ConvertDouble();
            String serv;
            serv = ConvertDouble.converterDoubleString(osfinalizadas.get(tb.getSelectedRow()).getServicoTerceiro());
            lblServTerceiro.setText(String.valueOf(serv));
            String mo2;
            mo2 = ConvertDouble.converterDoubleString(osfinalizadas.get(tb.getSelectedRow()).getMaoObra());
            lblMo.setText(String.valueOf(mo2));
            
            
            String subtotal2;
            subtotal2 = ConvertDouble.converterDoubleString(osfinalizadas.get(tb.getSelectedRow()).getSubTotal());
            lblSubt.setText(String.valueOf(subtotal2));
            String desconto2;
            desconto2 = ConvertDouble.converterDoubleString(osfinalizadas.get(tb.getSelectedRow()).getDesconto());
            lblDescont.setText(String.valueOf(desconto2));
            String total2;
            total2 = ConvertDouble.converterDoubleString(osfinalizadas.get(tb.getSelectedRow()).getTotal());
            lblTot.setText(String.valueOf(total2));
            Date ddd;
            ddd = osfinalizadas.get(tb.getSelectedRow()).getDataos();
            
            java.util.Date d = ddd;
            String dd;
            dd = String.valueOf(formato.format(d));
            lblDataConsulta.setText(dd);
            
            String vpago2;
            vpago2 = ConvertDouble.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getValorPago());
            lblValorPago.setText(vpago2);
            String resta2;
            resta2 = ConvertDouble.converterDoubleString(osfinalizadas.get(tbOSFinalizadas.getSelectedRow()).getResta());
            lblResta.setText(resta2);
            /*Date dv;
            String ddv = "";
            dv= osfinalizadas.get(tb.getSelectedRow()).getDataValidade();
            ddv = String.valueOf(formato.format(dv));
            lblDtVencimento.setText(ddv);
            //codproduto = vendasfinalizadas.get(tb.getSelectedRow()).getIDProduto();
            //qtd = vendasfinalizadas.get(tb.getSelectedRow()).getQtd();
           
            */
            
            
            while (tmItens.getRowCount() > 0){
                tmItens.removeRow(0);
            }
            
            /*codos = osfinalizadas.get(tb.getSelectedRow()).getCodOs();
            OSControl vc = new OSControl();
            itensOs = vc.listarItens(codos);
            String [] camposItens = new String[] {null, null, null, null, null};
            for(int t = 0; t < itensOs.size(); t++){
            
            tmItens.addRow(camposItens);
            tmItens.setValueAt(itensOs.get(t).getIdproduto(), t, 0);
            tmItens.setValueAt(itensOs.get(t).getDescricaoproduto(), t, 1);
            tmItens.setValueAt(itensOs.get(t).getMarca(), t, 2);
            tmItens.setValueAt(itensOs.get(t).getPreco(), t, 3);
            tmItens.setValueAt(itensOs.get(t).getQtdOs(), t, 4);*/
            codos = osfinalizadas.get(tb.getSelectedRow()).getCodOs();
            OSControl vc = new OSControl();
            osdet = vc.listarItens(codos);
            String [] camposItens = new String[] {null, null, null, null, null};
            for(int t = 0; t < osdet.size(); t++){
            
            tmItens.addRow(camposItens);
            tmItens.setValueAt(osdet.get(t).getIdproduto(), t, 0);
            tmItens.setValueAt(osdet.get(t).getDescricaoproduto(), t, 1);
            tmItens.setValueAt(osdet.get(t).getMarca(), t, 2);
            tmItens.setValueAt(osdet.get(t).getPreco(), t, 3);
            tmItens.setValueAt(osdet.get(t).getQtdOs(), t, 4);
            
        } 
          
       
       
       
        } else {
            
        
        
       }
        /*  VerificarData vd = new VerificarData();
         if (vd.verificarData(dat)){
            lblDtVencimento.setForeground(Color.red);
            //JOptionPane.showMessageDialog(null, "Orçamento expirou a data de validade!", "Erro", JOptionPane.ERROR_MESSAGE); 
        }else{
            lblDtVencimento.setForeground(Color.black);
        }
       */
        }catch (Exception e){
           e.printStackTrace();
       }
        
    }
    
    protected void fechar(){
       // cbProdutos.setEnabled(false);
            mo = 0;
            subtotal = 0;
            total = 0;
            servicoterceiro = 0;
            resta = 0;
            valorpago = 0;
            tfProduto.setText("");
            
            
        /*    orcamentospendentes.clear();
            orcamentos.clear();
            produt.clear();*/
            
           
        
        ftfQuantidade.setValue(1);
        tbOS.removeAll();
        if(os != null){
while (os.size()>0){
            os.remove(0);            
        }
        }
        if(osdet != null){
while (osdet.size()>0){
            osdet.remove(0);            
        }
        }
        if(osfinalizadas != null){
while (osfinalizadas.size()>0){
            osfinalizadas.remove(0);            
        }
        }
        if(produt != null){
while (produt.size()>0){
            produt.remove(0);           
        }
        }
        
while (tmOS.getRowCount()>0){
            tmOS.removeRow(0);
            
        }
//while (produtos.size()>0){
   //         produtos.remove(0);           
  //      }

while (tmOSFinalizadas.getRowCount() > 0){
                tmOSFinalizadas.removeRow(0);
            }
while (tmItens.getRowCount() > 0){
                tmItens.removeRow(0);
            }

//dataIni.setDate(null);
//dataFim.setDate(null);

    
    }
    
    
    public String extenso(){
        FormatoDeExtenso fe =new FormatoDeExtenso() {

             @Override
             public String getUnidadeInteiraNoSingular() {
                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             }

             @Override
             public String getUnidadeInteiraNoPlural() {
                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             }

             @Override
             public String getUnidadeDecimalNoSingular() {
                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             }

             @Override
             public String getUnidadeDecimalNoPlural() {
                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             }

             @Override
             public int getCasasDecimais() {
                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             }
         };
        
         NumericToWordsConverter converter;  
converter = new NumericToWordsConverter(new FormatoDeReal());  
String numero1;
numero1 = String.valueOf(valorpago);
numero1 = numero1.replace(",", ".");
double numero = Double.parseDouble(numero1); 
    String bosta;
             
bosta = converter.toWords(numero);  
extenso = "(" + bosta + ")";
  
        return extenso;
    } 
    
    
     private void Recibo(){
         try{
             extenso();
            Connection con = new AcessoMySql().conectar();
            HashMap parametros = new HashMap();
           // parametros.put("SUBREPORT_DIR", "/Outros/");
            ImageIcon gto = new ImageIcon(getClass().getResource("/Icons/CompetenteOS.jpg"));
             parametros.put("logo", gto.getImage());
             parametros.put("extenso", extenso);
            parametros.put("IDOS_OS", codos );
            
            //BuscaImage bi = new BuscaImage();
            //Image logo;
            //logo = bi.BuscaImage(1);
            
            
            //parametros.put("logo", logo);
            
            //JasperPrint jp = JasperFillManager.fillReport("./jasper/GooldcarOS.jasper",parametros, con);
            //JasperPrint jp = JasperFillManager.fillReport("/Outros/GooldcarOS.jasper",parametros, con);
            JasperPrint jp = JasperFillManager.fillReport("./jasper/COMPETENTERecibo.jasper",parametros, con);
            JasperViewer jrv= new JasperViewer(jp, false); // implementando o "FALSE" Impede que a aplicação seja encerrada ao fechar o relatório
           
            jrv.setVisible(true);
            
        }catch(Exception e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "Nao encontrado");
        }
    }
    private void comprovanteOS(){
         try{
            Connection con = new AcessoMySql().conectar();
            HashMap parametros = new HashMap();
           // parametros.put("SUBREPORT_DIR", "/Outros/");
            ImageIcon gto = new ImageIcon(getClass().getResource("/Icons/CompetenteOS.jpg"));
             parametros.put("logo", gto.getImage());
            parametros.put("IDOS_OS", codos );
            //BuscaImage bi = new BuscaImage();
            //Image logo;
            //logo = bi.BuscaImage(1);
            
            
            //parametros.put("logo", logo);
            
            //JasperPrint jp = JasperFillManager.fillReport("./jasper/GooldcarOS.jasper",parametros, con);
            //JasperPrint jp = JasperFillManager.fillReport("/Outros/GooldcarOS.jasper",parametros, con);
            JasperPrint jp = JasperFillManager.fillReport("./jasper/COMPETENTEOS.jasper",parametros, con);
            JasperViewer jrv= new JasperViewer(jp, false); // implementando o "FALSE" Impede que a aplicação seja encerrada ao fechar o relatório
           
            jrv.setVisible(true);
            
        }catch(Exception e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "Nao encontrado");
        }
    }
    
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        Tela = new javax.swing.JTabbedPane();
        JCadastrar = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbVendas1 = new javax.swing.JTable();
        Cabecalho = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lblCodigo = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblData = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        tfProduto = new javax.swing.JTextField();
        btInserir = new javax.swing.JButton();
        btExcluir = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        ftfQuantidade = new JFormattedTextField(NumberFormat.getNumberInstance());
        jLabel2 = new javax.swing.JLabel();
        tfCliente = new javax.swing.JTextField();
        tfStatus = new javax.swing.JTextField();
        btVerStatus = new javax.swing.JButton();
        btVerCliente = new javax.swing.JButton();
        tfFuncionario = new javax.swing.JTextField();
        btVerFuncionario = new javax.swing.JButton();
        rodape = new javax.swing.JPanel();
        lbltotal = new javax.swing.JLabel();
        lblDesconto = new javax.swing.JLabel();
        lblSubtotal = new javax.swing.JLabel();
        ftfSubtotal = new JFormattedTextField(DecimalFormat.getInstance());
        ftfDesconto = new JFormattedTextField(DecimalFormat.getInstance());
        ftfTotal = new JFormattedTextField(DecimalFormat.getInstance());
        jLabel9 = new javax.swing.JLabel();
        ftfServicoTerceiros = new JFormattedTextField(DecimalFormat.getInstance());
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        ftfMO = new JFormattedTextField(DecimalFormat.getInstance());
        tfObs = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        ftfValorPago = new JFormattedTextField(DecimalFormat.getInstance());
        jLabel4 = new javax.swing.JLabel();
        ftfResta = new JFormattedTextField(DecimalFormat.getInstance());
        Botoes = new javax.swing.JPanel();
        btNovo = new javax.swing.JButton();
        btFinalizar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        btComprovante = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbOS = new javax.swing.JTable();
        btVerForma = new javax.swing.JButton();
        btVerConds = new javax.swing.JButton();
        tfCond = new javax.swing.JTextField();
        tfForma = new javax.swing.JTextField();
        JConsultar = new javax.swing.JPanel();
        lblCod = new javax.swing.JLabel();
        lblClient = new javax.swing.JLabel();
        lblFunc = new javax.swing.JLabel();
        lblForm = new javax.swing.JLabel();
        lblCond = new javax.swing.JLabel();
        lblSubt = new javax.swing.JLabel();
        lblDescont = new javax.swing.JLabel();
        lblTot = new javax.swing.JLabel();
        btPesq = new javax.swing.JButton();
        btExcluirVenda = new javax.swing.JButton();
        dataFim = new com.toedter.calendar.JDateChooser();
        dataIni = new com.toedter.calendar.JDateChooser();
        lblDataConsulta = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        lblDtVencimento = new javax.swing.JLabel();
        lblTelefone = new javax.swing.JLabel();
        lblCelular = new javax.swing.JLabel();
        lblOperadora = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tbItens = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tbOSFinalizadas = new javax.swing.JTable();
        lblServTerceiro = new javax.swing.JLabel();
        lblMo = new javax.swing.JLabel();
        btAprovar = new javax.swing.JButton();
        btCancelarOS = new javax.swing.JButton();
        btAguardando = new javax.swing.JButton();
        btAlterar = new javax.swing.JButton();
        btComprovante1 = new javax.swing.JButton();
        lblValorPago = new javax.swing.JLabel();
        lblResta = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("VENDAS");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                teste(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                fecharForm(evt);
            }
        });

        Tela.setToolTipText("");
        Tela.setPreferredSize(new java.awt.Dimension(800, 720));

        tbVendas1.setModel(tmOS);
        tbOS.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmOs = tbOS.getSelectionModel();
        lsmOs.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    tbVendasLinhaSelecionada(tbOS);
                }
            }
        });
        jScrollPane2.setViewportView(tbVendas1);

        jLabel1.setText("Codigo");

        lblCodigo.setToolTipText("");

        jLabel5.setText("Data");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Inserção e Remoção de Itens", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        tfProduto.setEnabled(false);

        btInserir.setText("Inserir");
        btInserir.setToolTipText("");
        btInserir.setEnabled(false);
        btInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btInserirActionPerformed(evt);
            }
        });

        btExcluir.setText("Excluir Item");
        btExcluir.setEnabled(false);
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });

        jLabel11.setText("QTD");

        ftfQuantidade.setEnabled(false);

        jLabel2.setText("Código ou Descrição do Produto");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(tfProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel11)
                .addGap(18, 18, 18)
                .addComponent(ftfQuantidade, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btInserir, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftfQuantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(btInserir)
                    .addComponent(btExcluir)
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tfCliente.setToolTipText("");
        tfCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Cliente"));
        tfCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfClienteActionPerformed(evt);
            }
        });

        tfStatus.setToolTipText("");
        tfStatus.setBorder(javax.swing.BorderFactory.createTitledBorder("Status"));

        btVerStatus.setText("...");
        btVerStatus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVerStatusActionPerformed(evt);
            }
        });

        btVerCliente.setText("...");
        btVerCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVerClienteActionPerformed(evt);
            }
        });

        tfFuncionario.setBorder(javax.swing.BorderFactory.createTitledBorder("Serviço executado por"));

        btVerFuncionario.setText("...");
        btVerFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVerFuncionarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout CabecalhoLayout = new javax.swing.GroupLayout(Cabecalho);
        Cabecalho.setLayout(CabecalhoLayout);
        CabecalhoLayout.setHorizontalGroup(
            CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CabecalhoLayout.createSequentialGroup()
                .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CabecalhoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(tfStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btVerStatus)
                        .addGap(18, 18, 18)
                        .addComponent(tfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btVerCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblData, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CabecalhoLayout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tfFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btVerFuncionario)))
                .addContainerGap())
        );
        CabecalhoLayout.setVerticalGroup(
            CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CabecalhoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tfStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btVerStatus)
                        .addComponent(tfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btVerCliente))
                    .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(lblCodigo)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(CabecalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tfFuncionario))
                    .addComponent(btVerFuncionario))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        CabecalhoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, lblCodigo});

        CabecalhoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel5, lblData});

        rodape.setBorder(javax.swing.BorderFactory.createTitledBorder("Calculos"));

        lbltotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbltotal.setText("Total R$");

        lblDesconto.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblDesconto.setText("Desconto R$");

        lblSubtotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSubtotal.setText("Subtotal");

        ftfSubtotal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        ftfSubtotal.setEnabled(false);

        ftfDesconto.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        ftfDesconto.setEnabled(false);

        ftfTotal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        ftfTotal.setEnabled(false);
        ftfTotal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                total(evt);
            }
        });

        jLabel9.setText("Serviços de Terceiros R$");

        ftfServicoTerceiros.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        ftfServicoTerceiros.setEnabled(false);

        jLabel10.setText("OBS.:");

        jLabel12.setText("Mão de Obra");

        ftfMO.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        ftfMO.setEnabled(false);

        tfObs.setEnabled(false);

        jLabel3.setText("Valor Pago");

        ftfValorPago.setEnabled(false);
        ftfValorPago.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                recalc(evt);
            }
        });

        jLabel4.setText("Resta");
        jLabel4.setToolTipText("");

        ftfResta.setEditable(false);
        ftfResta.setEnabled(false);

        javax.swing.GroupLayout rodapeLayout = new javax.swing.GroupLayout(rodape);
        rodape.setLayout(rodapeLayout);
        rodapeLayout.setHorizontalGroup(
            rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rodapeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel12)
                        .addComponent(lblSubtotal)))
                .addGap(18, 18, 18)
                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rodapeLayout.createSequentialGroup()
                        .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(rodapeLayout.createSequentialGroup()
                                .addComponent(ftfSubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel9)
                                .addGap(18, 18, 18)
                                .addComponent(ftfServicoTerceiros, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(rodapeLayout.createSequentialGroup()
                                .addComponent(ftfMO, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lbltotal, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(25, 25, 25)
                                .addComponent(ftfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(rodapeLayout.createSequentialGroup()
                                .addComponent(lblDesconto)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ftfDesconto, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                            .addGroup(rodapeLayout.createSequentialGroup()
                                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(rodapeLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(ftfValorPago))
                                    .addGroup(rodapeLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(ftfResta))))))
                    .addComponent(tfObs))
                .addContainerGap())
        );
        rodapeLayout.setVerticalGroup(
            rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rodapeLayout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ftfSubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSubtotal)
                    .addComponent(jLabel9)
                    .addComponent(ftfServicoTerceiros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftfDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(ftfMO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbltotal, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(ftfValorPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(ftfResta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(rodapeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfObs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btNovo.setText("Nova OS");
        btNovo.setActionCommand("Novo Orcarmento");
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });

        btFinalizar.setText("Registrar OS");
        btFinalizar.setToolTipText("");
        btFinalizar.setActionCommand("Registrar Orcamento");
        btFinalizar.setEnabled(false);
        btFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btFinalizarActionPerformed(evt);
            }
        });

        btCancelar.setText("Cancelar OS");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        btComprovante.setText("Gerar Comprovante");
        btComprovante.setEnabled(false);
        btComprovante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btComprovanteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout BotoesLayout = new javax.swing.GroupLayout(Botoes);
        Botoes.setLayout(BotoesLayout);
        BotoesLayout.setHorizontalGroup(
            BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BotoesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BotoesLayout.createSequentialGroup()
                        .addComponent(btNovo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btFinalizar))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BotoesLayout.createSequentialGroup()
                        .addComponent(btComprovante)
                        .addGap(35, 35, 35)
                        .addComponent(btCancelar)))
                .addContainerGap())
        );
        BotoesLayout.setVerticalGroup(
            BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btNovo)
                    .addComponent(btFinalizar))
                .addGap(33, 33, 33)
                .addGroup(BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelar)
                    .addComponent(btComprovante))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Itens da OS"));

        tbOS.setModel(tmOS);
        tbOS.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmOs = tbOS.getSelectionModel();
        lsmOs.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    tbVendasLinhaSelecionada(tbOS);
                }
            }
        });
        jScrollPane1.setViewportView(tbOS);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                .addContainerGap())
        );

        btVerForma.setText("...");
        btVerForma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVerFormaActionPerformed(evt);
            }
        });

        btVerConds.setText("...");
        btVerConds.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVerCondsActionPerformed(evt);
            }
        });

        tfCond.setToolTipText("");
        tfCond.setBorder(javax.swing.BorderFactory.createTitledBorder("Condição de Pagamento"));

        tfForma.setToolTipText("");
        tfForma.setBorder(javax.swing.BorderFactory.createTitledBorder("Forma de Pagamento"));

        javax.swing.GroupLayout JCadastrarLayout = new javax.swing.GroupLayout(JCadastrar);
        JCadastrar.setLayout(JCadastrarLayout);
        JCadastrarLayout.setHorizontalGroup(
            JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JCadastrarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Cabecalho, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, JCadastrarLayout.createSequentialGroup()
                        .addComponent(rodape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfForma, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfCond, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JCadastrarLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(btVerConds))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JCadastrarLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(btVerForma)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 190, Short.MAX_VALUE)
                        .addComponent(Botoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19)))
                .addContainerGap())
        );
        JCadastrarLayout.setVerticalGroup(
            JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JCadastrarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Cabecalho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rodape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Botoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(JCadastrarLayout.createSequentialGroup()
                        .addGroup(JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfForma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btVerForma))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(JCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfCond, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btVerConds))))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        Tela.addTab("Cadastrar", JCadastrar);

        lblCod.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Codigo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblClient.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblFunc.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Funcionario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblForm.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Forma PGTO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblCond.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Condição PGTO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblSubt.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Subtotal", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblDescont.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Desconto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblTot.setToolTipText("");
        lblTot.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        btPesq.setText("Pesquisar");
        btPesq.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPesqActionPerformed(evt);
            }
        });

        btExcluirVenda.setText("Excluir");
        btExcluirVenda.setEnabled(false);
        btExcluirVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirVendaActionPerformed(evt);
            }
        });

        dataFim.setBorder(javax.swing.BorderFactory.createTitledBorder("Data FInal"));

        dataIni.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Inicio"));

        lblDataConsulta.setBorder(javax.swing.BorderFactory.createTitledBorder("Data do Orçamento"));

        lblStatus.setForeground(new java.awt.Color(0, 0, 255));
        lblStatus.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Status", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblDtVencimento.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data de Validade", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblTelefone.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Telefone", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblCelular.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Celular", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblOperadora.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Operadora", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ITENS DO ORÇAMENTO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        tbItens.setModel(tmItens);
        jScrollPane3.setViewportView(tbItens);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ORÇAMENTOS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        tbOSFinalizadas.setModel(tmOSFinalizadas);
        tbOSFinalizadas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmOSFinalizadas = tbOSFinalizadas.getSelectionModel();
        lsmOSFinalizadas.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    tbOrcamentosPendentesLinhaSelecionada(tbOSFinalizadas);
                }
            }
        });
        jScrollPane4.setViewportView(tbOSFinalizadas);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblServTerceiro.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Serviço de Terceiros", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblMo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mão de Obra", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        btAprovar.setText("Concluir OS");
        btAprovar.setEnabled(false);
        btAprovar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAprovarActionPerformed(evt);
            }
        });

        btCancelarOS.setText("Cancelar OS");
        btCancelarOS.setEnabled(false);
        btCancelarOS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarOSActionPerformed(evt);
            }
        });

        btAguardando.setText("Em execução");
        btAguardando.setEnabled(false);
        btAguardando.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAguardandoActionPerformed(evt);
            }
        });

        btAlterar.setText("Alterar OS");
        btAlterar.setEnabled(false);
        btAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarActionPerformed(evt);
            }
        });

        btComprovante1.setText("Gerar Comprovante");
        btComprovante1.setEnabled(false);
        btComprovante1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btComprovante1ActionPerformed(evt);
            }
        });

        lblValorPago.setBorder(javax.swing.BorderFactory.createTitledBorder("Valor Pago"));

        lblResta.setBorder(javax.swing.BorderFactory.createTitledBorder("Resta"));

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JConsultarLayout = new javax.swing.GroupLayout(JConsultar);
        JConsultar.setLayout(JConsultarLayout);
        JConsultarLayout.setHorizontalGroup(
            JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(JConsultarLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JConsultarLayout.createSequentialGroup()
                        .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblDataConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblDtVencimento, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(547, 547, 547)
                        .addComponent(lblCod, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(JConsultarLayout.createSequentialGroup()
                        .addComponent(lblClient, javax.swing.GroupLayout.PREFERRED_SIZE, 463, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblFunc, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblOperadora, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(JConsultarLayout.createSequentialGroup()
                        .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JConsultarLayout.createSequentialGroup()
                                .addComponent(lblForm, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblCond, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(JConsultarLayout.createSequentialGroup()
                                .addComponent(btAguardando)
                                .addGap(83, 83, 83)
                                .addComponent(btAprovar)
                                .addGap(33, 33, 33)
                                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton1)
                                    .addGroup(JConsultarLayout.createSequentialGroup()
                                        .addComponent(btCancelarOS)
                                        .addGap(33, 33, 33)
                                        .addComponent(btAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(18, 18, 18)
                        .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JConsultarLayout.createSequentialGroup()
                                .addComponent(lblSubt, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblServTerceiro, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(JConsultarLayout.createSequentialGroup()
                                        .addComponent(lblMo, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblDescont, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(JConsultarLayout.createSequentialGroup()
                                        .addGap(128, 128, 128)
                                        .addComponent(lblTot, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(21, 21, 21)
                                        .addComponent(lblValorPago, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(30, 30, 30)
                                        .addComponent(lblResta, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(JConsultarLayout.createSequentialGroup()
                                .addComponent(dataIni, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(dataFim, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btPesq, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btComprovante1)
                                .addGap(18, 18, 18)
                                .addComponent(btExcluirVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))))))
        );
        JConsultarLayout.setVerticalGroup(
            JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JConsultarLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDataConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDtVencimento, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCod, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblClient, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFunc, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblOperadora, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblForm, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(JConsultarLayout.createSequentialGroup()
                        .addComponent(lblCond, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1))
                    .addComponent(lblSubt, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblServTerceiro, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(JConsultarLayout.createSequentialGroup()
                        .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblMo, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblDescont, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(5, 5, 5)
                        .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTot, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblValorPago, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblResta, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JConsultarLayout.createSequentialGroup()
                        .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dataIni, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btPesq, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btComprovante1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btExcluirVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(dataFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(6, 6, 6))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JConsultarLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(JConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btAguardando, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btAprovar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btCancelarOS, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        Tela.addTab("Consultar", JConsultar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Tela, javax.swing.GroupLayout.DEFAULT_SIZE, 1468, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Tela, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE)
        );

        Tela.getAccessibleContext().setAccessibleName("");

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btInserirActionPerformed
        incluirProduto();
        
        
    }//GEN-LAST:event_btInserirActionPerformed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed
        novoCadastro();
        tipoalter = "alteraçãoinicial";
        tipocadastro = "cadastrar";
    }//GEN-LAST:event_btNovoActionPerformed

    private void btFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFinalizarActionPerformed
        if(tipocadastro.equals("cadastrar")){
        cadastrarOS();
        fechar();
        }else if (tipocadastro.equals("alteração")){
            alterarOS();
            fechar();
        }
       
    }//GEN-LAST:event_btFinalizarActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        if (tipoalter.equals("alteraçãoinicial")){
        removerProduto();
        }else if(tipoalter.equals("alteraçãoposterior")){
            removerProdutoAlter();
        }
            
    }//GEN-LAST:event_btExcluirActionPerformed

    private void fecharForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_fecharForm
         tbOSFinalizadas.getSelectionModel().clearSelection();
          tbOS.getSelectionModel().clearSelection();
        fechar();

    }//GEN-LAST:event_fecharForm

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        ftfSubtotal.setValue(0);
        ftfDesconto.setValue(0);
        ftfTotal.setValue(0);
        ftfServicoTerceiros.setValue(0);
        tfProduto.setText("");
        desabilitarCampos();
        fechar();
    }//GEN-LAST:event_btCancelarActionPerformed

    private void btPesqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPesqActionPerformed
        pesquisarOS();
        btExcluir.setEnabled(true);
        
    }//GEN-LAST:event_btPesqActionPerformed

    private void btExcluirVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirVendaActionPerformed
       excluirOSDet();
        excluirOS();
    }//GEN-LAST:event_btExcluirVendaActionPerformed

    private void teste(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_teste

    }//GEN-LAST:event_teste

    private void total(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_total
        /*mo = Double.parseDouble(ftfMO.getText());
        servicoterceiro = Double.parseDouble(ftfServicoTerceiros.getText());
        desconto = Double.parseDouble(ftfDesconto.getText());
            total = (subtotal - desconto) + servicoterceiro + mo;
            ftfTotal.setValue(total);*/
           Subtotal();
    }//GEN-LAST:event_total

    private void btCancelarOSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarOSActionPerformed
        codstatus = 3;
        aprovarOS();
        codstatus = null;
        codos = null;
        pesquisarOS();
    }//GEN-LAST:event_btCancelarOSActionPerformed

    private void btAprovarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAprovarActionPerformed

        codstatus = 2;
        aprovarOS();

        codstatus = null;
        codos = null;
        pesquisarOS();

    }//GEN-LAST:event_btAprovarActionPerformed

    private void btAguardandoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAguardandoActionPerformed
        codstatus = 1;
        aprovarOS();
        codstatus = null;
        codos = null;
        pesquisarOS();
    }//GEN-LAST:event_btAguardandoActionPerformed

    private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarActionPerformed
       try{ 
        habilitarCampos();
        setarCampos();
        tipoalter = "alteraçãoposterior";
        tipocadastro = "alteração";
        Tela.setSelectedIndex(0);
       }catch (Exception e){
           e.getMessage();
       }
    
        
    }//GEN-LAST:event_btAlterarActionPerformed

    private void tfClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfClienteActionPerformed

    private void btVerClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVerClienteActionPerformed
        listarClientes();
    }//GEN-LAST:event_btVerClienteActionPerformed

    private void btVerStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVerStatusActionPerformed
        listarStatus();
    }//GEN-LAST:event_btVerStatusActionPerformed

    private void btVerFormaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVerFormaActionPerformed
        listarFormas();
    }//GEN-LAST:event_btVerFormaActionPerformed

    private void btVerCondsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVerCondsActionPerformed
        listarConds();
    }//GEN-LAST:event_btVerCondsActionPerformed

    private void btComprovanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btComprovanteActionPerformed
        comprovanteOS();
    }//GEN-LAST:event_btComprovanteActionPerformed

    private void btComprovante1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btComprovante1ActionPerformed
        comprovanteOS();
        
    }//GEN-LAST:event_btComprovante1ActionPerformed

    private void btVerFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVerFuncionarioActionPerformed
        listarFuncionarios();
    }//GEN-LAST:event_btVerFuncionarioActionPerformed

    private void recalc(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_recalc
       Subtotal();
    }//GEN-LAST:event_recalc

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Recibo();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Orcamentos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Orcamentos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Orcamentos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Orcamentos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new OS().setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Orcamentos.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Orcamentos.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Orcamentos.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(Orcamentos.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Botoes;
    private javax.swing.JPanel Cabecalho;
    private javax.swing.JPanel JCadastrar;
    private javax.swing.JPanel JConsultar;
    private javax.swing.JTabbedPane Tela;
    private javax.swing.JButton btAguardando;
    private javax.swing.JButton btAlterar;
    private javax.swing.JButton btAprovar;
    public javax.swing.JButton btCancelar;
    private javax.swing.JButton btCancelarOS;
    private javax.swing.JButton btComprovante;
    private javax.swing.JButton btComprovante1;
    public javax.swing.JButton btExcluir;
    public javax.swing.JButton btExcluirVenda;
    public javax.swing.JButton btFinalizar;
    public javax.swing.JButton btInserir;
    public javax.swing.JButton btNovo;
    public javax.swing.JButton btPesq;
    private javax.swing.JButton btVerCliente;
    private javax.swing.JButton btVerConds;
    private javax.swing.JButton btVerForma;
    private javax.swing.JButton btVerFuncionario;
    private javax.swing.JButton btVerStatus;
    public com.toedter.calendar.JDateChooser dataFim;
    public com.toedter.calendar.JDateChooser dataIni;
    public javax.swing.JFormattedTextField ftfDesconto;
    public javax.swing.JFormattedTextField ftfMO;
    public javax.swing.JFormattedTextField ftfQuantidade;
    private javax.swing.JFormattedTextField ftfResta;
    public javax.swing.JFormattedTextField ftfServicoTerceiros;
    public javax.swing.JFormattedTextField ftfSubtotal;
    public javax.swing.JFormattedTextField ftfTotal;
    private javax.swing.JFormattedTextField ftfValorPago;
    private javax.swing.JButton jButton1;
    public javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblCelular;
    public javax.swing.JLabel lblClient;
    public javax.swing.JLabel lblCod;
    public javax.swing.JLabel lblCodigo;
    public javax.swing.JLabel lblCond;
    private javax.swing.JLabel lblData;
    public javax.swing.JLabel lblDataConsulta;
    public javax.swing.JLabel lblDescont;
    public javax.swing.JLabel lblDesconto;
    public javax.swing.JLabel lblDtVencimento;
    public javax.swing.JLabel lblForm;
    public javax.swing.JLabel lblFunc;
    private javax.swing.JLabel lblMo;
    private javax.swing.JLabel lblOperadora;
    private javax.swing.JLabel lblResta;
    private javax.swing.JLabel lblServTerceiro;
    private javax.swing.JLabel lblStatus;
    public javax.swing.JLabel lblSubt;
    public javax.swing.JLabel lblSubtotal;
    private javax.swing.JLabel lblTelefone;
    public javax.swing.JLabel lblTot;
    private javax.swing.JLabel lblValorPago;
    public javax.swing.JLabel lbltotal;
    private javax.swing.JPanel rodape;
    public javax.swing.JTable tbItens;
    public javax.swing.JTable tbOS;
    public javax.swing.JTable tbOSFinalizadas;
    public javax.swing.JTable tbVendas1;
    public javax.swing.JTextField tfCliente;
    public javax.swing.JTextField tfCond;
    public javax.swing.JTextField tfForma;
    private javax.swing.JTextField tfFuncionario;
    public javax.swing.JTextField tfObs;
    private javax.swing.JTextField tfProduto;
    public javax.swing.JTextField tfStatus;
    // End of variables declaration//GEN-END:variables
}
